var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,
    $ = layui.jquery,
    laydate = layui.laydate;

layui.use(['tableEdit',"excel"], function () {
    let tableEdit = layui.tableEdit;
    let layer = layui.layer,
        excel = layui.excel;


    lay('.starttime').each(function(){
        laydate.render({
            elem: this
        });
    });

    //表单刷新
    form.render();
    let initData = [];
    table.render({
        elem: '#paymentSelect'
        ,data:initData
        ,toolbar: '#paymentToolbar'
        ,totalRow: true
        ,cols: [[
              {field: 'numbers',width: 50,type:'numbers',title:'序号'}
            , {field: 'productCode', title: '产品编码', sort: true, width: 120, align: 'center'}
            , {field: 'specificationCode', title: '规格编码', sort: true, width: 200, align: 'center'}
            , {field: 'productCdesc', title: '中文描述', sort: true, width: 120, align: 'center'}
            , {field: 'productEdesc', title: '英文描述', sort: true, width: 120, align: 'center'}
            , {field: 'productCname', title: '中文名称', sort: true, width: 120, align: 'center'}
            , {field: 'productEname', title:'英文名称',sort:true,width: 120, align: 'center'}
            , {field: 'purchaseCurrency', title: '采购币种', sort: true, width: 200, align: 'center'}
            , {field: 'taxIncludedCost', title:'含税出厂价',sort:true,width: 120, align: 'center'}
            , {field: 'untaxedCost', title: '未税出厂价', sort: true, width: 200, align: 'center'}
            , {field: 'partsCode', title:'配件编码',sort:true,width: 120, align: 'center'}
        ]]
        ,id: 'maininformationtableid'
        ,height: $(document).height() - $('#paymentSelect').offset().top - 75,
        //开启分页
        page: true,
        limits: [300,600,900],
    });


    //搜索提交
    form.on('submit(submitform)', function(data){
        table.reload('maininformationtableid', {
            page: {
                limit:300,
                curr: 1
            },
            url:'receivePayment/productStatisticsByPage',
            where:  data.field
        }, 'data');
        return false;
    });


    form.on('submit(exportData)', function (queryReq) {
        let index = layer.load(2, {
            shade: [0.4, '#000'],
            content: '加载中...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '40px',
                    'width': '200px'
                });
            }
        });
        $.ajax({
            data: queryReq.field,
            url:"receivePayment/productStatisticsExport",
            success: function(res) {
                if(res.status == 200){
                    //配置列宽
                    let colConf = excel.makeColConfig({
                        'A': 80,
                        'X': 80
                    }, 80);
                    excel.exportExcel({
                        sheet1: res.data.data
                    }, '产品统计.xlsx', 'xlsx', {
                        extend: {
                            '!cols': colConf
                        }
                    });
                }else {
                    layer.msg(res.msg, {icon: 5});
                }
                layer.close(index);
                return false;
            }
        });
        return false;
    });


});
